package patch.com.patch;

import android.app.Activity;
import android.util.Log;
import android.widget.TextView;

import com.taobao.android.dexposed.DexposedBridge;
import com.taobao.android.dexposed.XC_MethodHook;
import com.taobao.android.dexposed.XposedHelpers;
import com.taobao.patch.IPatch;
import com.taobao.patch.PatchParam;

/**
 * Created by Administrator on 2015/8/27.
 */
public class ViewPatch implements IPatch {
    @Override
    public void handlePatch(PatchParam patchParam) throws Throwable {

        Log.e("sss","ViewPath---- handlepath");
        Class<?> cls = null;
        try {
            cls = patchParam.context.getClassLoader().loadClass("com.taobao.dexposed.TestActivity");
        }catch (ClassNotFoundException e){
            e.printStackTrace();
            Log.e("sss", "ViewPath---- ClassNotFoundException"+e.toString());
            return;
        }

        DexposedBridge.findAndHookMethod(cls, "initView", new XC_MethodHook() {

            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                Activity activity = (Activity)param.thisObject;
                TextView textView = (TextView) XposedHelpers.getObjectField(activity,"textLabel");
                textView.setText("这是补上的值");
                Log.e("sss", "ViewPath---- beforeHookedMethod");
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                Activity activity = (Activity)param.thisObject;
                Log.e("sss","ViewPath---- afterHookedMethod");
                TextView textView = (TextView) XposedHelpers.getObjectField(activity,"textLabel");
                textView.setText("这是后补上的值");
            }
        });
    }
}
